package com.java.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.java.common.enums.CategoryLevelEnum;
import com.java.common.utils.PageUtils;
import com.java.common.utils.Query;
import com.java.mapper.CategoryDao;
import com.java.pojo.Category;
import com.java.pojo.vo.CategoryVO;
import com.java.pojo.vo.NewItemsVO;
import com.java.service.CategoryService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("categoryService")
public class CategoryServiceImpl extends ServiceImpl<CategoryDao, Category> implements CategoryService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<Category> page = this.page(
                new Query<Category>().getPage(params),
                // 拼接查询条件
                new LambdaQueryWrapper<Category>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<Category> queryAllRootLevelCat() {
        return this.baseMapper.selectList(new LambdaQueryWrapper<Category>().eq(Category::getType, CategoryLevelEnum.FIRST_LEVEL.code));
    }

    @Override
    public List<CategoryVO> getSubCatList(Integer rootCatId) {
        return this.baseMapper.getSubCatList(rootCatId);
    }

    @Override
    public List<NewItemsVO> getSixNewItemLazy(Integer rootCatId) {
        return this.baseMapper.getSixNewItemLazy(rootCatId);
    }

}